package veterinaria.servlet.vacuna;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.Doctor;
import veterinaria.modelo.Vacuna;
import veterinaria.negocio.GestionDoctores;
import veterinaria.negocio.GestionVacunas;


/**
 * Servlet implementation class DocInsertar
 */
@WebServlet("/VacInsertar")
public class VacInsertar extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public VacInsertar() {
    	super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		String nombre = request.getParameter("txtnombre");
		String descripcion = request.getParameter("txtdescripcion");
		String stock = request.getParameter("txtstock");
		String precio = request.getParameter("txtprecio");
		
		int s = Integer.parseInt(stock);
		double p = Double.parseDouble(precio);
			GestionVacunas negocio = new GestionVacunas();
		
		try {
			Vacuna vacuna = negocio.insertar(nombre, descripcion, s, p);
			if (vacuna==null){
				response.sendRedirect(request.getContextPath()	+ "/vacunaError.jsp");
			}else{
				response.sendRedirect(request.getContextPath()	+ "/vacunaSatis.jsp");
			}
			
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	}

}
